// Soup1和Soup2展示了如何通过将所有构造器设为 pirvate 来阻止直接创建类的对象。
// Soup1创建了一个静态方法，用来生成Soup1的新对象并返回对它的引用。
// Soup2使用了所谓的设计模式(design pattern)，称为单例模式(Singleton)，因为它从始至终都只有一个对象被创建。

public class ClassAccess {
    void testPrivate() {
        // 'Soup1()' has private access in 'Soup1'
        // Soup1 s = new Soup1();  // Error: Cannot create
    }

    void testStatic() {
        Soup1 s = Soup1.makeSoup();
    }

    void testSingleton() {
        Soup2.access().f();
    }

    public static void main(String[] args) {
        ClassAccess ca = new ClassAccess();
        ca.testPrivate();
        ca.testStatic();
        ca.testStatic();
        ca.testSingleton();
        ca.testSingleton();
    }
}

class Soup1 {
    private Soup1() {
    }

    public static Soup1 makeSoup() {
        Soup1 soup1 = new Soup1();
        System.out.println(soup1.toString());
        return soup1;
    }
}

class Soup2 {
    private Soup2() {
    }

    private static Soup2 soup2 = new Soup2();

    public static Soup2 access() {
        System.out.println(soup2.toString());
        return soup2;
    }

    public void f() {
    }
}